﻿/*
	CaptivateLoader
	
	Sets up the CaptivatePlayer by setting styles,
	reading in the FlashVars.
	
    Created by Jesse R. Warden a.k.a. "JesterXL"
	jesterxl@jessewarden.com
	http://www.jessewarden.com
	
	This is release under a Creative Commons license. 
    More information can be found here:
    
    http://creativecommons.org/licenses/by/2.5/
*/
this._lockroot = true;
stop();

import mx.managers.PopUpManager;
import mx.controls.ProgressBar;
import mx.controls.TextArea;
import mx.containers.Window;

import com.jxl.captivate.CaptivatePlayer;


function init()
{
	Stage.removeListener(this);
	Stage.addListener(this);
	
	_global.style.setStyle("themeColor", "haloBlue");
	_global.style.setStyle("fontSize", 11);
	_global.style.setStyle("fontFamily", "Verdana,_sans");
	_global.style.setStyle("modalTransparency", 0);
	
	destroyObject("mc");
	createClassObject(CaptivatePlayer, "mc", 0);
	mc.addEventListener("playlistLoaded", this);
	mc.addEventListener("debug", this);
	mc.setVisible(false);
	
	progress_pb.deletePopUp();
	var p = PopUpManager.createPopUp(this, ProgressBar, false);
	progress_pb = p;
	progress_pb.move((Stage.width / 2) - (progress_pb.width / 2),
					 (Stage.height / 2) - (progress_pb.height / 2));
	progress_pb.mode = "manual";
	progress_pb.indeterminate = true;
	progress_pb.label = "Loading Playlist...";
	
	/*
	d = PopUpManager.createPopUp(this, Window, false);
	d.setSize(320, 240);
	d.title = "Debug Window";
	d.contentPath = TextArea.symbolName;
	_global.dw = d;
	_global.debug = function(o)
	{
		_global.dw.content.text += o + "\n";
	};
	*/
	
	
	
	// Deal with FlashVars
	if(playlist == null)
	{
		playlist = "captivate_playlist.xml";
	}
	
	if(autoplay != null)
	{
		if(autoplay == "false")
		{
			mc.autoPlay = false;
		}
		else if(autoplay == "true")
		{
			mc.autoPlay = true;
		}
	}
	
	if(volume != null)
	{
		volume = parseInt(volume);
		if(!isNaN(volume))
		{
			mc.setVolume(volume);
		}
	}
	
	if(scalecontent != null)
	{
		if(scalecontent == "false")
		{
			mc.setScaleContent(false);
		}
		else if(scalecontent == "true")
		{
			mc.setScaleContent(true);
		}
	}
	
	if(continousplayback != null)
	{
		mc.continousPlayback = continousplayback;
	}
	else
	{
		mc.continousPlayback = true;
	}
	
	if(looping != null)
	{
		mc.isLooping = looping;
	}
	else
	{
		mc.isLooping = false;
	}
	
	this.onEnterFrame = function()
	{
		mc.loadPlaylist(playlist);
		delete playlist;
		delete volume;
		delete scalecontent;
		delete continousplayback;
		delete looping;
		delete this.onEnterFrame;
	};
	
	onResize();
}

function playlistLoaded(event_obj:Object):Void
{
	trace("progress_pb: " + progress_pb);
	progress_pb.deletePopUp();
	trace("progress_pb: " + progress_pb);
	mc.setVisible(true);
}

function onResize()
{
	progress_pb.move((Stage.width / 2) - (progress_pb.width / 2),
					 (Stage.height / 2) - (progress_pb.height / 2));
	mc.setSize(Stage.width, Stage.height);
}

// start this mug
init();
